<template>
	<BaseContainer class="report-table-wrapper">
		<div class="r-header">
			<p>南京市养老机构综合运营补贴申请表</p>
			<p class="text-sm">
				（所属时间： <span class="text-underline">{{ model.year }}</span
				>年第<span class="text-underline"> </span
				>季度）
			</p>
		</div>
		<ReportTable
			:column="dataListBase"
			:isDetail="isDetail"
			:baseModel="baseModel.organizationInfoPO"
			:model="modelData.organizationInfoPO"
			@change="handleSave"
		></ReportTable>
		<ReportTable
			:column="dataListStaff"
			:isDetail="isDetail"
			:baseModel="baseModel.staffPO"
			:model="modelData.staffPO"
			@change="handleSave"
		></ReportTable>
		
		<ReportTable
			:key="applicationKey"
			:column="dataListApply"
			:isDetail="isDetail"
			:baseModel="baseModel.applicationContentPO"
			:model="modelData.applicationContentPO"
			@change="handleSave"
		>
		</ReportTable>

		<aplid-dialog @close="onClose" width="85%" v-model="visibleForm" append-to-body whickComm="Archives" :customeHeader="customeHeader" :model="nowOrgInfo">
			<transition name="fade" mode="out-in">
				<div class="dialog-content w-100" v-show="!Loading">
					<ServiceOrgArchives :showBtn="false" :nowRowData="nowOrgInfo"></ServiceOrgArchives>
				</div>
			</transition>
			<PageLoading v-if="Loading" />
		</aplid-dialog>

		<el-drawer size="65%" append-to-body v-model="drawer" :with-header="false"  @close="onClose">
			<practitioner :needPigeonhole="false" v-if="drawer" :isComprehensiveQueries="false" :actionBtn="false"/>
		</el-drawer>
	</BaseContainer>
</template>

<script setup lang="ts">
import { onUnmounted,watch,ref,shallowRef} from 'vue'
import ReportTable from '@/views/instOperate/components/ApplyReport/components/ReportTable/index.vue'
import apiMod from '@/apiMod'
import ServiceOrgArchives from '@/views/datacenter/basicData/serviceOrg/components/Archives/index.vue'
import practitioner from '@/views/datacenter/basicData/practitioner/index.vue'
import { useCommonStore } from '@/stores/common'
import {dealBigMoney,filterEmptyObj} from '@/utils/util'
const visibleForm = ref(false)
const {setTempParams,setGloablParams,setMoreSearch} = useCommonStore()
const { Loading } = storeToRefs(useCommonStore())

const props = defineProps<{
  creditCode?:string|number
	params?: any
	editData?: any
	isDetail?: boolean
  caseId?:string|number
  custome?: boolean
  approvalStatus?:string|number
}>()

let applicationKey = ref(0)
let tableData = ref({})
const baseModel: any = shallowRef({})
const modelData:any = ref({
	organizationInfoPO: {},
	staffPO: {},
	applicationContentPO: {},
})


const emit = defineEmits(['save'])

const model = ref({
	year: '',
	month: '',
})


const drawer = ref(false)
const nowOrgInfo = ref({})

const customeHeader = {
	type: 'CardOne',
	title: 'organizationName',
	avatar: 'organizationLogo',
	tipList: [{ prop: 'operateStatusLabel', type: 'tip-success', label: '运营状态' }],
	tagList: [{ prop: 'organizationTypeLabel', custome: 'tag', type: 'success', label: '机构类型' }],
	menuBtn: [],
}

const onClose = ()=> {
  setTempParams({})
  setGloablParams({})
  setMoreSearch({})
}


const  getCurrentQuarter =(nowMonth?:number|string)=> {
  const month:any =nowMonth|| new Date().getMonth() + 1;
  if (month >= 1 && month <= 3) {
    return 1;
  } else if (month >= 4 && month <= 6) {
    return 2;
  } else if (month >= 7 && month <= 9) {
    return 3;
  } else {
    return 4;
  }
}

const getServiceOrgInfo = (creditCode) => {
	if (!creditCode) return
	apiMod.view_dpServiceOrgBase_creditCode(creditCode).then((res) => {
		nowOrgInfo.value = res.data
		visibleForm.value = true
	})
}
const dataListBase = [
	[
		{
			m: '基 本 情 况',
			bl: 1,
			fs: 16,
			mc: {
				rs: 1,
				cs: 4,
			},
		},
	],
	[
		{ m: '机构名称', style: { width: '200px' } },
		{
			m: '',
			prop: 'ORG_NAME',
			link: true,
			showLink: (col, model) => {
				getServiceOrgInfo(model.creditCode)
			},
		},
		{ m: '法定代表人', style: { width: '200px' } },
		{ m: '', prop: 'LEGAL_NAME' },
	],
	[{ m: '机构地址' }, { m: '', prop: 'ORG_ADDRESS' }, { m: '联系电话' }, { m: '', prop: 'LEGAL_PHONE' }],
	[{ m: '机构等级' }, { m: '', prop: 'ORG_LEVEL' }, { m: '核定床位数' }, { m: '', prop: 'ORG_ROOM' }],
	[{ m: '营业执照（民非）证号' }, { m: '', prop: 'CREDIT_CODE' }, { m: '机构设置证号（备案）' }, { m: '', prop: 'FILING_CODE' }],
	[{ m: '开户银行' }, { m: '', prop: 'BANK_NAME' }, { m: '银行账号' }, { m: '', prop: 'BANK_ACCOUNT' }],
	[
		{
			m: '养老机构服务质量大检查指南基础指标是否全部达标',
			align: 'left',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
		{
			m: '（是/否）',
			prop: 'SERVICE_STANDARD',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
	],
]
const dataListStaff = [
	[
		{
			m: '员 工 概 况',
			bl: 1,
			fs: 16,
			link: true,
			linkType: 'list',
			style: { borderTop: '0px solid #fff' },
			mc: {
				rs: 1,
				cs: 8,
			},
			showLink: (col, model) => {
        const creditCode = modelData.value.organizationInfoPO.creditCode
        setGloablParams({creditCode:creditCode})
				drawer.value = true
			},
		},
	],
	[
		{ m: '员工总数' },
		{ m: '', prop: 'SATFF_NUM' },
		{ m: '持证人数' },
		{ m: '', prop: 'SATFF_CERT_NUM' },
		{ m: '管理人员' },
		{ m: '', prop: 'MANAGER_NUM' },
		{ m: '持证人数' },
		{ m: '', prop: 'MANAGER_CERT_NUM' },
	],
]

const applyConfigBase:any = ref([
	[
		{
			m: '申 请 内 容',
			bl: 1,
			fs: 16,
			style: { borderTop: '0px solid #fff' },
			mc: {
				rs: 1,
				cs: 9,
			},
		},
	],
	[
		{
			m: '月份',
			mc: {
				rs: 2,
				cs: 1,
			},
		},
		{
			m: '机构等级',
			mc: {
				rs: 2,
				cs: 1,
			},
		},
		{
			m: '介 助',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
		{
			m: '介 护',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
		{
			m: '基准补贴总金额',
			mc: {
				rs: 2,
				cs: 1,
			},
			
		},
		{
			m: '等级系数',
			mc: {
				rs: 2,
				cs: 1,
			},
			
		},
		{
			m: '基准总金额×等级系数',
			mc: {
				rs: 2,
				cs: 1,
			},
			
		},
	],
	[{ m: '人' }, { m: '金额' }, { m: '人' }, { m: '金额' }],
	
])
const dataListApply:any= ref([
	
])

const dataListFooter = [
	[
		{
			m: '审核意见',
			bl: 1,
			fs: 16,
			style: { borderTop: '0px solid #fff' },
			mc: {
				rs: 1,
				cs: 9,
			},
		},
	],
	[
		{
			m: '区民政部门意见',
			mc: {
				rs: 1,
				cs: 2,
			},
		},
		{
			m: '',
			prop: 'opinion',
			mc: {
				rs: 1,
				cs: 7,
			},
		},
	],
]
// 处理数据

watch(()=>props.editData,(newVal)=>{
	if(newVal&&newVal.applyDetails){
		let data = JSON.parse(props.editData.applyDetails)
		tableData.value = data
		modelData.value.organizationInfoPO = data
		modelData.value.staffPO = data
		modelData.value.applicationContentPO = data
		if(data.smzjSqnr.length>0){
			data.smzjSqnr.forEach(el=>{
				applyConfigBase.value.push(
					[{m:'',propName:el['MONTH']},{m:'',propName:el['ORG_LEVEL']},{m:'',propName:el['CARE_HELP_NUM']},{m:'',propName:el['CARE_HELP_AMOUNT']},{m:'',propName:el['CARE_NURSE_NUM']},{m:'',propName:el['CARE_NURSE_AMOUNT']},{m:'',propName:el['BASE_AMOUNT_TOTAL']},{m:'',propName:el['LEVEL_PERCENT']},{m:'',propName:el['AMOUNT_TOTAL']}]
				)
			})
			dataListApply.value = [
			...applyConfigBase.value,
			[
				{
					m: '补贴金额:',
					align: 'left',
					mc: {
						rs: 1,
						cs: 3,
					},
					propName:tableData.value['APPLY_AMOUNT']
				},
				{
					m: '大写:',
					align: 'left',
					mc: {
						rs: 1,
						cs: 6,
					},
					propName:tableData.value['APPLY_AMOUNT_CN']
				},
			],
		
			]
			applicationKey.value = Math.random()
		}
		
	}
},{
	immediate:true,
	deep:true
})
onMounted(() => {
	
})
const handleSave = () => {
	emit('save', modelData.value, 'report_1001', props.editData)
}
onUnmounted(() => {
	// emit('save', modelData.value, 'report_1001',props.editData)
})
</script>

<style scoped lang="scss">
.text-underline {
    text-decoration: underline;
    padding: 0 6px;
}
.report-table-wrapper {
	width: 85%;
	margin: 0 auto;
	padding: 10px 30px;
	top: 0;

	.r-header {
		text-align: center;
		font-size: 18px;
		font-weight: bold;
		padding: 15px 0;

		.text-sm {
			font-weight: 400;
			font-size: 16px;
		}
	}
}
</style>
